home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS01.ADF / C / Dotty.c < prev    next >
C/C++ Source or Header  |  1985-12-04  |  4KB  |  146 lines

  1. /* dotty window demo v1.0 */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/nodes.h>
  5. #include <exec/lists.h>
  6. #include <exec/ports.h>
  7. #include <graphics/gfx.h>
  8. #include <graphics/clip.h>
  9. #include <graphics/view.h>
  10. #include <graphics/rastport.h>
  11. #include <graphics/layers.h>
  12. #include <intuition/intuition.h>
  13.  
  14. struct IntuitionBase *IntuitionBase;
  15. struct GfxBase *GfxBase;
  16.  
  17. #define DEPTH   2
  18.  
  19. #define WIDTH  100
  20. #define HEIGHT 50
  21.  
  22. int waiting_for_message = FALSE;
  23.  
  24. char dotty[] = "Dotty Window";
  25.  
  26. int usable_width(w)
  27. struct Window *w;
  28. {
  29.    return (w->Width - w->BorderLeft - w->BorderRight);
  30. }
  31.  
  32. int usable_height(w)
  33. struct Window *w;
  34. {
  35.    return(w->Height - w->BorderTop - w->BorderBottom);
  36. }
  37.  
  38. main()
  39. {
  40.    struct RastPort *rp;
  41.    struct Window *window;
  42.    struct NewWindow nw;
  43.    int x,y,c;
  44.    int xoffset,yoffset;
  45.    int width,height;
  46.    struct IntuiMessage *message;
  47.    ULONG MessageClass;
  48.  
  49.    if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",1)))
  50.    {
  51.       printf("no graphics library!!!\n");
  52.       exit(1);
  53.    }
  54.  
  55.    if (!(IntuitionBase = (struct IntuitionBase *)
  56.                            OpenLibrary("intuition.library",1)) )
  57.    {
  58.       CloseLibrary(GfxBase);
  59.       printf("no intuition here!!\n");
  60.       exit(1);
  61.    }
  62.  
  63.    nw.LeftEdge = 50;
  64.    nw.TopEdge = 50;
  65.    nw.Width = WIDTH;
  66.    nw.Height = HEIGHT;
  67.    nw.DetailPen = -1;
  68.    nw.BlockPen = -1;
  69.    nw.IDCMPFlags = CLOSEWINDOW
  70.                  | REFRESHWINDOW
  71.                  | SIZEVERIFY
  72.                  | NEWSIZE;
  73.    nw.Flags = WINDOWDEPTH
  74.             | WINDOWSIZING
  75.             | WINDOWDRAG
  76.             | WINDOWCLOSE
  77.             | SIMPLE_REFRESH;
  78.    nw.FirstGadget = NULL;
  79.    nw.CheckMark = NULL;
  80.    nw.Title = dotty;
  81.    nw.Screen = NULL;
  82.    nw.BitMap = NULL;
  83.  
  84.    nw.MinHeight = 10;
  85.    nw.MinWidth = 10;
  86.    nw.MaxHeight = 200;
  87.    nw.MaxWidth = 640;
  88.  
  89.    nw.Type = WBENCHSCREEN;
  90.  
  91.    if (!(window = (struct Window *)OpenWindow(&nw) ))
  92.    {
  93.       printf("could not open the window\n");
  94.       CloseLibrary(IntuitionBase);
  95.       CloseLibrary(GfxBase);
  96.       exit(2);
  97.    }
  98.    width = usable_width(window);
  99.    height = usable_height(window);
  100.    rp = window->RPort;
  101.    xoffset = window->BorderLeft;
  102.    yoffset = window->BorderTop;
  103.    while (TRUE)      /* do this forever, or until user gets bored */
  104.    {
  105.       while (!(message = (struct IntuiMessage *)GetMsg(window->UserPort)) )
  106.       {
  107.          if (waiting_for_message)   Wait(1<<window->UserPort->mp_SigBit);
  108.          else
  109.          {
  110.             x = RangeRand(width);
  111.             y = RangeRand(height);
  112.             c = RangeRand(32);
  113.             SetAPen(rp,c);
  114.             WritePixel(rp,xoffset+x,yoffset+y);
  115.          }
  116.       }
  117.       MessageClass = message->Class;
  118.       ReplyMsg(message);
  119.       switch (MessageClass)
  120.       {
  121.          case CLOSEWINDOW  :  CloseWindow(window);
  122.                               CloseLibrary(IntuitionBase);
  123.                               CloseLibrary(GfxBase);
  124.                               exit(0);
  125.  
  126.         case SIZEVERIFY   :  waiting_for_message = TRUE;
  127.                              break;
  128.  
  129.         case REFRESHWINDOW:  BeginRefresh(window);
  130.                              SetAPen(rp,0);
  131.                              /* should not have to recalculate these */
  132.                              width = usable_width(window);
  133.                              height = usable_height(window);
  134.                              RectFill(rp,xoffset,yoffset,
  135.                                          xoffset+width-1,yoffset+height-1);
  136.                              EndRefresh(window,TRUE);
  137.                              break;
  138.  
  139.         case NEWSIZE      :  waiting_for_message = FALSE;
  140.                              width = usable_width(window);
  141.                              height = usable_height(window);
  142.                              break;
  143.      }
  144.   }
  145. }
  146.